import Vue from 'vue'
import Router from 'vue-router'
import home from '@/view/home'
import car from '@/view/car'
import menu from '@/view/menu'
import my from '@/view/my'
import order from '@/view/order'
import login from '@/view/login'
Vue.use(Router)

let router =  new Router({
  routes: [
    {
        path:'/',
        name:'home',
        component:home
    },
    {
        path:'/car',
        name:'car',
        component:car
    },
    {
        path:'/menu',
        name:'menu',
        component:menu
    },
    {
        path:'/my',
        name:'my',
        component:my
    },
    {
        path:'/order',
        name:'order',
        component:order
    },
    {
        path:'/login',
        name:'login',
        component:login
    }
  ]
})

export default router;

router.beforeEach((to,from,next) => {
    if(to.name === 'car'){
        if(localStorage.getItem('isLogin')){
            next();
        }else{
            next('/login')
        }
    }else{
        next();
    }
})

